package com.aaa.service.impl;

import com.aaa.mapper.SalaryMapper;
import com.aaa.pojo.Salary;
import com.aaa.service.SalaryService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * @author bSu
 * @date 2020/6/1 - 15:21
 */
@Service
public class SalaryServiceImpl implements SalaryService {
    @Autowired
    private SalaryMapper sm;

    @Override
    @Cacheable("salary")
    @Transactional //事务
    public PageInfo<Salary> selectAll(Integer pageNum,Integer pageSize) {

        System.out.println("service第几页："+pageNum);
        PageHelper.startPage(pageNum,pageSize);
        List<Salary> salaries = sm.selectAll();
        PageInfo<Salary> info =new PageInfo<Salary>(salaries);
        System.out.println(info);
        return info;
    }

    @Override
    //@Transactional //事务
    public int updateByPrimaryKeySelective(Salary record) {
        int i = sm.updateByPrimaryKeySelective(record);
        return i;
    }

    @Transactional //事务
    @Override
    public int insertSelective(Salary record) {
        record.setCreateDate(new Date());
        int i = sm.insertSelective(record);
        return i;
    }

    @Override
    @Transactional //事务
    public int deleteByPrimaryKey(Integer id) {
        return sm.deleteByPrimaryKey(id);
    }

    @Override
    @Transactional //事务
    public Salary selectByPrimaryKey(Integer id) {
        return sm.selectByPrimaryKey(id);
    }
}
